Skip to content

Add configurable caching strategies for Motif scopes - #276

Merged
rysh88 merged 1 commit into
mainfrom
feature/motif-caching-strategies
Jul 28, 2026
Merged

Add configurable caching strategies for Motif scopes#276
rysh88 merged 1 commit into
mainfrom
feature/motif-caching-strategies

Conversation

@rysh88

@rysh88 rysh88 commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Description:

Introduce four opt-in caching strategies, selectable per @Scope, so applications can tune dependency-caching behavior. Default behavior (BASELINE) is unchanged.

Strategies (motif.CachingStrategy):

  • BASELINE: the default behavior we have today — None.NONE sentinel + synchronized(this)
  • BASELINE_WITH_LOCK_SELECTABLE: BASELINE plus optional per-dependency locks (MotifRuntimeConfig.usePerDependencyLock)
  • SMART_CACHE: null-initialized cache fields with double-checked locking; supports per-dependency locks
  • RUNTIME_SELECTABLE: generates both variants behind a wrapper that delegates based on MotifRuntimeConfig.cachingStrategy — switchable at runtime, making it A/B-test friendly

Other changes:

  • Runtime config surface: MotifRuntimeConfig, MotifLock, CachingStrategy
  • @DoNotCache gains onlyForSmartCacheMode() for strategy-specific opt-out
  • Codegen updated in JavaCodeGenerator / KotlinCodeGenerator
  • BaselineCodegenTest guards BASELINE codegen byte-for-byte against drift

Related issue(s):

Test plan: Unit tests, including concurrency tests (latch handshake for deterministic lock verification, 16-thread contention test for double-checked locking).

Revert plan: Opt-in per @Scope via CachingStrategy; default is BASELINE.

@rysh88
rysh88 force-pushed the feature/motif-caching-strategies branch 2 times, most recently from 7721d26 to a860619 Compare July 21, 2026 19:04
Comment thread .github/workflows/ci.yml Outdated
strategy:
matrix:
java_version: [11]
java_version: [17]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use 21 in internal repos now but okay to leave it as is

.build()
} else {
// SMART_CACHE: Use null initialization
FieldSpec.builder(Object::class.java, name, Modifier.PRIVATE, Modifier.VOLATILE).build()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the type is a kotlin non-nullable type

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For KotlinCodeGenerator, internally, the global property will be nullable but the return type will be non-null.

image image

- Add CachingStrategy enum (NONE, BASELINE, BASELINE_WITH_LOCK_SELECTABLE)
- Add DoNotCache annotation and MotifRuntimeConfig for runtime config
- Add MotifLock for per-dependency locking support
- Generate caching code based on strategy in Java/Kotlin code generators
- Fix CI: upgrade Java 11 → 17 (required by AGP 7.4.2)
- Fix google-java-format 1.8 → 1.17.0 (required by Java 17)
- Fix AndroidManifest package attribute conflicts with namespace
- Fix dagger-comparison R import to match namespace

Co-Authored-By: Claude
@rysh88
rysh88 force-pushed the feature/motif-caching-strategies branch from a860619 to 48a3dbc Compare July 28, 2026 11:51
@rysh88
rysh88 merged commit 919c2fc into main Jul 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants